using System;
using System.Collections.Generic;
using System.Linq;

namespace Nvigorate.Repository.Test
{
    public class Person : 
        BaseEntity<int>,
        IMyOtherCarIsAMearas,
        IRegisterVehicle
    {
        public virtual string FirstName { get; set; }
        public virtual string LastName { get; set; }
        public virtual int Age { get; set; }

        public virtual IList<Vehicle> Vehicles { get; set; }

        public virtual void AddVehicle(Vehicle vehicle)
        {
            if(!vehicle.Drivers.Contains(this))
                vehicle.Drivers.Add(this);
            Vehicles.Add(vehicle);

            DomainNotification.Send(new DomainEvent<Person, Vehicle>()
                                          {
                                              Root = this,
                                              Entity = vehicle,
                                              Message = string.Format("A new vehicle was successfully registered for {0} {1}", this.FirstName, this.LastName)
                                          });
        }
        
        public virtual bool RidesAMearas()
        {
            return Vehicles.Any(v => v.Make == "Mearas");
        }

        public Person()
        {
            Vehicles = new List<Vehicle>();
        }
    }

    public interface IMyOtherCarIsAMearas
    {
        bool RidesAMearas();
    }

    public interface IRegisterVehicle
    {
        void AddVehicle(Vehicle vehicle);
    }
}